/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sunsite.action;

import com.opensymphony.xwork2.ActionSupport;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import org.springframework.context.support.ResourceBundleMessageSource;
import sunsite.po.ProjectExp;
import sunsite.po.Resume;
import sunsite.po.SocietyJob;
import sunsite.po.University;
import sunsite.po.Usr;
import sunsite.service.UserService;
import sunsite.tools.ContextHelper;
import sunsite.tools.Naming;
import sunsite.vo.UserInfo;

/**
 *
 * @author mg
 */
public class SubmitResume extends ActionSupport {

    private String type;
    private String position;
    private String sex;
    private String identifier;
    private String mobile;
    private String selfDescription;
    private String awards;
    private String english;
    private String resumeUrl;
    private String resumeUrlEn;
    private String photoUrl;
    private String fullName;
    private int university;
    private String major;
    private String degree;
    private String grade;
    private List<ProjectExp> projectExps;
    private List<SocietyJob> societyJobs;
    private UserService usrService;
    private ResourceBundleMessageSource messageSource;
    private String message;

    public void setMessageSource(ResourceBundleMessageSource messageSource) {
        this.messageSource = messageSource;
    }

    public void setUsrService(UserService usrService) {
        this.usrService = usrService;
    }

    @Override
    public String execute() throws Exception {
        Resume r = (Resume) ContextHelper.getSession().get(Naming.SessionName.Resume);
        if (r == null) {
            message = messageSource.getMessage("message.notLogin", null, Locale.getDefault());
            return SUCCESS;
        }
        if (type != null && type.equals("1")) {
            r.setPosition(position);
            r.setSex(sex);
            r.setMobile(mobile);
            r.setIdentifier(identifier);
            r.setSelfDescription(selfDescription);
            ContextHelper.getSession().put(Naming.SessionName.Resume, r);

            Usr usr = r.getUsr();
            usr.setFullName(fullName);
            usr.setDegree(degree);
            usr.setUniversity(new University(Integer.valueOf(university)));
            usr.setMajor(major);
            usr.setGrade(grade);
            this.usrService.update(usr);
            return "project";
        } else if (type != null && type.equals("2")) {
            Set<ProjectExp> exps = new HashSet();
            for (ProjectExp projectExp : projectExps) {
                if ((projectExp.getProName() == null || projectExp.getProName().equals("")) && (projectExp.getProDesc() == null || projectExp.getProDesc().equals(""))) {
                    continue;
                } else {
                    projectExp.setExpId("exp" + System.nanoTime());
                    exps.add(projectExp);
                }
            }
            r.setProjectExp(exps);
            ContextHelper.getSession().put(Naming.SessionName.Resume, r);
            return "social";
        } else if (type != null && type.equals("3")) {
            Set<SocietyJob> jobs = new HashSet();
            for (SocietyJob societyJob : this.societyJobs) {
                if ((societyJob.getJobDesc() == null || societyJob.getJobDesc().equals("")) ) {
                    continue;
                } else {
                    societyJob.setJobId("job" + System.nanoTime());
                    jobs.add(societyJob);
                }
            }
            r.setSocietyJob(jobs);
            ContextHelper.getSession().put(Naming.SessionName.Resume, r);
            return "final";
        }
        return SUCCESS;
    }

    public String getAwards() {
        return awards;
    }

    public void setAwards(String awards) {
        this.awards = awards;
    }

    public String getEnglish() {
        return english;
    }

    public void setEnglish(String english) {
        this.english = english;
    }

    public String getIdentifier() {
        return identifier;
    }

    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getPhotoUrl() {
        return photoUrl;
    }

    public void setPhotoUrl(String photoUrl) {
        this.photoUrl = photoUrl;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public List<ProjectExp> getProjectExps() {
        return projectExps;
    }

    public void setProjectExps(List<ProjectExp> projectExps) {
        this.projectExps = projectExps;
    }

    public String getResumeUrl() {
        return resumeUrl;
    }

    public void setResumeUrl(String resumeUrl) {
        this.resumeUrl = resumeUrl;
    }

    public String getResumeUrlEn() {
        return resumeUrlEn;
    }

    public void setResumeUrlEn(String resumeUrlEn) {
        this.resumeUrlEn = resumeUrlEn;
    }

    public String getSelfDescription() {
        return selfDescription;
    }

    public void setSelfDescription(String selfDescription) {
        this.selfDescription = selfDescription;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public List<SocietyJob> getSocietyJobs() {
        return societyJobs;
    }

    public void setSocietyJobs(List<SocietyJob> societyJobs) {
        this.societyJobs = societyJobs;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getDegree() {
        return degree;
    }

    public void setDegree(String degree) {
        this.degree = degree;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public String getGrade() {
        return grade;
    }

    public void setGrade(String grade) {
        this.grade = grade;
    }

    public String getMajor() {
        return major;
    }

    public void setMajor(String major) {
        this.major = major;
    }

    public int getUniversity() {
        return university;
    }

    public void setUniversity(int university) {
        this.university = university;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
